$(function(){
	$("#cancleBut").click(function(){
		parent.$('#dlg').window('close');
		parent.$(document.body).remove()
	});
	if(Number($('#backtotal').val())<Number($('.count').text())){
		$('.reshidden').show();
	}
	$("input",$("#backtotal").next("span")).blur(function(){  
		if(Number($('#backtotal').val())<Number($('.count').text())){
			$('.reshidden').show();
		}
		else{
			$('.reshidden').val('');
			$('.reshidden').hide();
		}
	})
	var codelength=$('#backtotal').width();
	$('#backtotal').validatebox({
		required: true,
	    tipPosition:'top',
	    deltaX:codelength/4,
	    validType: 'intOrFloat',
	});
	$('#remark').validatebox({
	    required: false,
	    tipPosition:'top',
	    validType: {maxLength:[255]},
	    deltaX:codelength/4
	});
	
	//提交表单
	$("#submitBut").click(function(){
		if(Number($('#backtotal').val())<Number($('.count').text())&&$('#reason').val()==''){
			$.messager.alert('失败','返款金额小于统计金额，需填写原因','error');
			return;
		}
		if(Number($('#backtotal').val())>Number($('.count').text())){
			$.messager.alert('失败','返款金额不可大于统计金额','error');
			return;
		}
		$("#form").form('submit',{
			url:'/backinfo/updateBackInfo',
			onSubmit:function(){
		        return $(this).form('validate');
		    },
		    success:function(data){
		    	var jdata=$.parseJSON(data); 
		        if(jdata.code==200){
		        	$.messager.alert('成功','修改成功','info',function(){
		        		parent.$('#dlg').window('close');
		        		window.parent.refreshTab("返款信息");
		        	});
		        }
		        else{
		        	$.messager.alert('失败',jdata.msg,'error');
		        }
		    }
		});
	})
})